// 支持链式调用的关键是每次返回此类
class math {
    constructor(initVal = 0) {
        this.num = initVal
    }

    add(...args){
        // reduce第二个参数为初始值
        this.num = args.reduce((a,b)=> a + b,this.num)
        // 必须是return this  this指向类 这样才能继续链式调用
        return this
    }
    minus(...args){
        this.num -= args.reduce((a,b)=> a + b)
        return this
    }
    times(timer){
        this.num = timer * this.num;
        return this
    }

}
let ma = new math()
console.log(ma.add(1, 2).minus(1).times(2));
